﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using InterfacesInstanceClustering;
using InterfacesTransformation;
using DAL;
using DTO;

namespace MyVectorizer
{
    public partial class ThreeTypeVectorizerPlugin : IVectorizerUC, IVectorizer
    {
        public ThreeTypeVectorizerPlugin()
        {
            InitializeComponent();
        }

        private IInstanceClusteringHost pluginHost = null;
        public IInstanceClusteringHost PluginHost
        {
            get
            {
                return pluginHost;
            }
            set
            {
                this.pluginHost = value;
            }
        }

        private string pluginName = "Three Types Evaluater";
        public string PluginName
        {
            get
            {
                return this.pluginName;
            }
        }

        private string pluginDescription = "Evaluate ";

        public string PluginDescription
        {
            get { return pluginDescription; }
            set { pluginDescription = value; }
        }

        public IVectorizerUC PluginUserControl
        {
            get
            {
                return this;
            }
        }

        public void Initialize()
        {
        }

        public void PluginDispose()
        {
        }

        public DTO.Vector Vectorize(int webpageID
            , List<string> webpageAnnotatedKeyword
            , List<Webtag> splitWebtagList
            , List<string> metaStr
            , string splitWebpageTitle
            , List<string> commonTerms)
        {
            this.vectorMaker.MakeDictionary(webpageAnnotatedKeyword, splitWebtagList, metaStr, splitWebpageTitle);
            
            return this.vectorMaker.MakeVector(webpageID, commonTerms);            
        }

        WeightVector weightVector = new WeightVector();

        public WeightVector WeightVector
        {
            get { return weightVector; }
            set { weightVector = value; }
        }

        VectorMaker vectorMaker = new VectorMaker();

        public VectorMaker VectorMaker
        {
            get { return vectorMaker; }
            set { vectorMaker = value; }
        }

        private void button_WVSet_Click(object sender, EventArgs e)
        {
            if (!this.textBox_WV.Text.Equals(string.Empty))
            {
                string[] dimentions = this.textBox_WV.Text.Split(new char[] { ',', '(', ')', ' ' }, StringSplitOptions.RemoveEmptyEntries);                

                if (dimentions.Length != 3)
                {
                    MessageBox.Show("Please enter a three dimentional vector!");
                }
                else
                {
                    double[] tempValue = new double[dimentions.Length];
                    for (int i = 0; i < dimentions.Length; i++)
                    {
                        try
                        {
                            tempValue[i] = double.Parse(dimentions[i]);
                        }
                        catch
                        {
                            MessageBox.Show("Please enter the right format of a vector!");
                            return;
                        }
                    }

                    weightVector = new WeightVector(tempValue[0], tempValue[1], tempValue[2]);
                    MessageBox.Show("Vector Setting succeeded!");
                }
            }
            else
            {
                MessageBox.Show("Please enter vector values into the textbox!");
            }
        }
    }
}
